package view.component;

import org.zkoss.zk.ui.event.MouseEvent;

import view.helper.CardHolder;

public class CardComponent extends CardHolder {	

	public CardComponent(String imgPath) {
		super("image/"+imgPath+".png");
		setDraggable(imgPath);
	}
	
	public void draw() {
			drawAtDepth(topHolder.getStep(this));
	}
	
	private void drawAtDepth(Integer depth) {		
		super.drawAtPosition(depth, 0);
		//System.out.println("card: "+getDraggable()+" topHolder+++: "+topHolder );
		if (lastCard!=null) {
			lastCard.drawAtDepth(topHolder.getStep(lastCard));		
		}
	}
	
	public void setZindex(int zindex) {		
		this.zindex = zindex;
		if (lastCard!=null) {
			lastCard.setZindex(zindex+10);
		}
	}
	
	public void setTopHolder(CardHolder topHolder) {
		this.topHolder = topHolder;
		if (lastCard!=null) {
			lastCard.setTopHolder(topHolder);
		}
	}
	
	public int getQueueCount() {
		if (lastCard==null) {
			return 1;
		} else {
			return lastCard.getQueueCount() + 1;
		}
	}
	
	public void onDoubleClick(MouseEvent evt) {
		CardHolder anyEndCell = adaptor.getEndCells()[0];
		updateAdaptor(this, anyEndCell);
		//System.out.println("dblClkd");
	}
		
	/*
	public void onClick(MouseEvent evt) {
		
	}
	*/

}
